
package pe.edu.upc.dew.pharma.dao.mysql;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.stereotype.Repository;

import pe.edu.upc.dew.pharma.dao.CategoriaDao;
import pe.edu.upc.dew.pharma.dao.mapper.CategoriaMapper;
import pe.edu.upc.dew.pharma.dao.mapper.ProductoMapper;
import pe.edu.upc.dew.pharma.model.Categoria;
import pe.edu.upc.dew.pharma.model.Producto;
import pe.edu.upc.dew.pharma.util.StoredProcedurePharma;

@Repository
public class MysqlCategoriaDao extends SimpleJdbcDaoSupport implements CategoriaDao{

	private static final Log logger = LogFactory.getLog(MysqlCategoriaDao.class);
	
	@Autowired
	public MysqlCategoriaDao(DataSource dataSource){
		setDataSource(dataSource);
	}
	
	public List<Categoria> listarCategorias(){
		List<Categoria> listarCategorias = new ArrayList<Categoria>();
		StoredProcedurePharma sp = new StoredProcedurePharma(getJdbcTemplate(), "sp_listadoCategorias");
		Map<String, Object> result = sp.executeProcedure("categorias", new CategoriaMapper());
		listarCategorias = (List<Categoria>) result.get("categorias");
		return listarCategorias;
	}
}
